<template>
  <div class="full-box shadow-box padding-box">
    <OperateCommon :showSearch="true" :showAdd="false" @search="initData">
      <template #condition>
        <div class="condition-item">
          <el-input
            v-model="queryParams.object_name"
            placeholder="按项目名称关键字查询"
            clearable
          ></el-input>
        </div>
        <div class="condition-item">
          <el-date-picker
            style="width: 150px"
            v-model="queryParams.start_date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="开始时间"
            clearable
          >
          </el-date-picker>
        </div>
        <div class="condition-item">
          <el-date-picker
            style="width: 150px"
            v-model="queryParams.end_date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="结束时间"
            clearable
          >
          </el-date-picker>
        </div>
      </template>
    </OperateCommon>
    <div class="table-wrapper">
      <BaseTable
        :columns="columns"
        :showSort="true"
        :tableData="tableData"
        :pages="{
          show: true,
          count: count,
        }"
        :operate="{
          show: true,
          width: 200,
        }"
        @pagination="pageChange"
      >
        <template #operate="{ current }">
          <!-- <el-button
            type="success"
            size="mini"
            :disabled="parseInt(current.row.red_solve_status) > 0"
            @click="linkWhere(current.row)"
            >交办</el-button
          >
          <el-button
            type="warning"
            size="mini"
            :disabled="parseInt(current.row.red_solve_status) != 10"
            @click="withDraw(current)"
            >撤回</el-button
          > -->
          <el-button type="primary" size="mini" @click="linkWhere(current.row)"
            >详情</el-button
          >
          <el-button
            type="danger"
            size="mini"
            @click="deleteConfirm(current.row.id)"
            >删除</el-button
          >
        </template>
      </BaseTable>
    </div>
  </div>
</template>

<script>
import BaseTable from "@/components/Common/BaseTable.vue";
import OperateCommon from "@/components/Common/OperateCommon.vue";
import LinkTo from "@/mixins/LinkTo";
import {
  getRedAlerAssignList,
  postAssignWithDrawal,
} from "@/api/RedAlert/Index";
export default {
  mixins: [LinkTo],
  components: { BaseTable, OperateCommon },
  data() {
    return {
      columns: columns,
      tableData: [],
      count: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        object_name: "",
        start_date: "",
        end_date: "",
        dept_id: "",
        assign_status: "",
      },
    };
  },
  methods: {
    initData() {
      if (!this.queryParams.start_date) {
        this.queryParams.start_date = "";
      }
      if (!this.queryParams.end_date) {
        this.queryParams.end_date = "";
      }
      getRedAlerAssignList(this.queryParams).then((res) => {
        if (res.code == 0) {
          this.tableData = res.data.map((i) => {
            switch (parseInt(i.red_solve_status)) {
              case 0:
                i.red_solve_statusText = "未交办";
                break;
              case 10:
                i.red_solve_statusText = "已交办";
                break;
              case 15:
                i.red_solve_statusText = "交办退回";
                break;
              case 20:
                i.red_solve_statusText = "待处置";
                break;
              case 100:
                i.red_solve_statusText = "已处置";
                break;
            }

            return i;
          });
          this.count = res.num;
        }
      });
    },
    pageChange(val) {
      this.queryParams.pageNum = val.pageNum;
      this.queryParams.pageSize = val.pageSize;
      this.initData();
    },
    deleteConfirm(id) {
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.deleteItem(id);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    deleteItem(id) {
      deleteDept({ id: id }).then((res) => {
        if (res.code == 0) {
          this.$message.success("删除成功");
          this.initData();
        }
      });
    },
    linkWhere(item) {
      this.linkTo(`/redAlert/details/${item.id}/3`);
    },
    withDraw(item) {
      postAssignWithDrawal({
        id: item.row.id,
        assign_id: item.row.assign_id,
      }).then((res) => {
        if (res.code == 0) {
          this.$message.success("撤回成功");
          this.initData();
        }
      });
    },
  },
  created() {
    this.initData();
  },
};

const columns = [
  {
    prop: "object_name",
    label: "项目名称",
    width: "",
    minWidth: "300",
    align: "",
  },
  {
    prop: "dept_name",
    label: "预警单位",
    width: "",
    minWidth: "200",
    align: "",
  },
  {
    prop: "description",
    label: "预警监控点",
    width: "",
    minWidth: "300",
    align: "",
  },
  {
    prop: "trigger_time",
    label: "预警发生时间",
    width: "200",
    minWidth: "",
    align: "",
  },
  {
    prop: "red_solve_statusText",
    label: "处置状态",
    width: "100",
    minWidth: "",
    align: "",
  },
  {
    prop: "assign_time",
    label: "交办日期",
    width: "200",
    minWidth: "",
    align: "",
  },
];
</script>

<style lang="scss" scoped>
</style>